[TOOLS] Avoid unaligned accesses in libfsimage FAT16 code
authorTim Deegan <Tim.Deegan@xensource.com>
Wed, 8 Aug 2007 11:26:21 +0000 (12:26 +0100)
committerTim Deegan <Tim.Deegan@xensource.com>
Wed, 8 Aug 2007 11:26:21 +0000 (12:26 +0100)
Signed-off-by: Kouya Shimura <kouya@jp.fujitsu.com>
Signed-off-by: KUWAMURA Shin'ya <kuwa@jp.fujitsu.com>
tools/libfsimage/fat/fsys_fat.c

index 9d74bdf1a9186cab61240728de490005b932002e..a0afb87f49fffe0001800d6adc95e186f81fe0fe 100644 (file)
@@ -228,15 +228,15 @@ fat_read (fsi_file_t *ffi, char *buf, int len)
              if (!devread (ffi, sector, 0, FAT_CACHE_SIZE, (char*) FAT_BUF))
                return 0;
            }
-         next_cluster = * (unsigned long *) (FAT_BUF + (cached_pos >> 1));
+         next_cluster = ((__u16 *) (FAT_BUF + (cached_pos >> 1)))[0];
          if (FAT_SUPER->fat_size == 3)
            {
              if (cached_pos & 1)
                next_cluster >>= 4;
              next_cluster &= 0xFFF;
            }
-         else if (FAT_SUPER->fat_size == 4)
-           next_cluster &= 0xFFFF;
+         else if (FAT_SUPER->fat_size > 4)
+           next_cluster |= ((__u16 *) (FAT_BUF + (cached_pos >> 1)))[1] << 16;
          
          if (next_cluster >= FAT_SUPER->clust_eof_marker)
            return ret;